* This file .\replication\figure_c10\figure_c10_eqls.do

* European Foundation for the Improvement of Living and Working Conditions. (2018). European Quality of Life Survey Integrated Data File, 2003-2016. [data collection]. 3rd Edition. UK Data Service. SN: 7348, http://doi.org/10.5255/UKDA-SN-7348-3
* Source: https://beta.ukdataservice.ac.uk/datacatalogue/studies/study?id=7348
* http://doi.org/10.5255/UKDA-SN-7348-3
* These data are safeguarded (https://ukdataservice.ac.uk/find-data/access-conditions/safeguarded-access/).
* To gain access to the data, please register an account with the UK Data Archive (https://ukdataservice.ac.uk/).

/*
use eqls_integrated_trend_2003-2016.dta, clear

rename *, lower

decode y16_country, gen(country)
kountry country, from(other) stuck
rename _ISO3N_ iso3n
drop if iso3n==.
kountry iso3n, from(iso3n) to(cown)
rename _COWN_ ccode
kountry iso3n, from(iso3n) to(iso3c)
rename _ISO3C_ iso3c
labmask ccode, val(iso3c)
tab ccode, m

recode wave (1=2003) (2=2007) (3=2011) (4=2016), gen(year)

clonevar weight=wcalib

* Missed mortgage payment 
* EQLS	EQLS 2012	Y11_Q60A	Question:
* Has your household been in arrears at any time during the past 12 months, that is, unable to pay as scheduled any of the following? Rent or mortgage payments for accommodation
* 1	Yes
* 2	No
* 98	(Don’t know)
* 99	(Refusal)

cap drop missedpayment?
gen missedpayment1=(y16_q93a==1) if inlist(y16_q93a,1,2) // Arrears	in	rent or mortgage payments
gen missedpayment2=(y16_q93b==1) if inlist(y16_q93b,1,2) // Arrears	in	utility bills, such as electricity,	water,	gas
gen missedpayment3=(y16_q93c==1) if inlist(y16_q93c,1,2) // Arrears	in	payments related to consumer loans
gen missedpayment4=(y16_q93d==1) if inlist(y16_q93d,1,2) // Arrears	in	telephone, mobile or internet bills
gen missedpayment5=(y16_q93e==1) if inlist(y16_q93e,1,2) // Arrears	in	payments related to informal loans
tabstat missedpayment?, by(ccode) f(%4.3f)
tabstat missedpayment?, by(year) f(%4.3f)

label var missedpayment1 "Q93a Arrears in rent or mortgage payments"
label var missedpayment2 "Q93b Arrears in utility bills, such as electricity,	water,	gas"
label var missedpayment3 "Q93c Arrears in payments related to consumer loans"
label var missedpayment4 "Q93d Arrears in telephone, mobile or internet bills"
label var missedpayment5 "Q93e Arrears in payments related to informal loans"

clonevar age=y16_hh2b
numlabel `: val label y16_empstatus_8categories_trend', add
tab y16_empstatus_8categories_trend
gen empl=(y16_empstatus_8categories_trend==1) if inrange(y16_empstatus_8categories_trend,1,7)
gen unempl=0 if empl==1
replace unempl=1 if inlist(y16_empstatus_8categories_trend,2,3)

// Income
clonevar HHincome=y16_income_quartiles
	* Y16_income_quartiles = Income quartiles based on equivalised household income

tabstat missedpayment?, by(HHincome) f(%4.3f)	

* missedpayment1 "Q93a Arrears in rent or mortgage payments"
* missedpayment2 "Q93b Arrears in utility bills, such as electricity,	water,	gas"
* missedpayment3 "Q93c Arrears in payments related to consumer loans"
* missedpayment4 "Q93d Arrears in telephone, mobile or internet bills"
* missedpayment5 "Q93e Arrears in payments related to informal loans"

keep if inlist(ccode,200, 205, 210, 211, 220, 230, 235, 255, 305, 325, 350, 375, 380, 385, 390)

collapse (mean) missedpayment? [aw=weight], by(y16_country ccode iso* HHincome)

label var missedpayment1 "Q93a Arrears in rent or mortgage payments"
label var missedpayment2 "Q93b Arrears in utility bills, such as electricity,	water,	gas"
label var missedpayment3 "Q93c Arrears in payments related to consumer loans"
label var missedpayment4 "Q93d Arrears in telephone, mobile or internet bills"
label var missedpayment5 "Q93e Arrears in payments related to informal loans"

label var missedpayment1 "Rent or mortgage"
label var missedpayment2 "Utility bills"
label var missedpayment3 "Consumer loans"
label var missedpayment4 "Phone/cable"
label var missedpayment5 "Informal loans"

foreach v of varlist missedpayment? {
	replace `v'=`v'*100
}

label val HHincome
decode y16_country, gen(country)
labmask ccode, val(country)

format missedpayment* %2.1f

drop if HHincome==.
keep country HHincome missedpayment1 missedpayment2 missedpayment3 
compress
note: .\replication\figure_c10\figure_c10_eqls.do
note: European Foundation for the Improvement of Living and Working Conditions. (2018). European Quality of Life Survey Integrated Data File, 2003-2016. [data collection]. 3rd Edition. UK Data Service. SN: 7348, http://doi.org/10.5255/UKDA-SN-7348-3
note: Source: https://beta.ukdataservice.ac.uk/datacatalogue/studies/study?id=7348
note: http://doi.org/10.5255/UKDA-SN-7348-3
note: Generated on `= c(current_date)'
saveold eqls_integrated_trend_2003-2016_extract.dta, version(12)
*/

use eqls_integrated_trend_2003-2016_extract.dta, clear

tw (connected missedpayment1 missedpayment2 missedpayment3  HHincome, sort ms(s Oh d)) ///
	, by(country, c(3) yrescale note("")) ///  imargin(vsmall)) ///
	xtitle("Income quartile") ///
	ytitle("Missed payment (%)" " ") ///
	xlabel(1(1)4, angle(0)) ///
	scheme(538bw) ///
	legend(r(1) size(small) region(lwidth(none))) ///
	ysize(6) xsize(4)
	
	
graph save   figure_c10.gph, replace
graph export figure_c10.pdf, replace
graph export figure_c10.emf, replace

